package com.example.web.permission;

import cn.dev33.satoken.stp.StpInterface;
import com.example.common.Interface.user.service.RolePermissionService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class UserPermission implements StpInterface {

    @DubboReference(check = false)
    private RolePermissionService rolePermissionService;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        // 本list仅做模拟，实际项目中要根据具体业务逻辑来查询权限
        List<String> list = rolePermissionService.getPermissionsByUserId(Long.valueOf(loginId.toString()));
        log.info("用户权限列表：" + list);
        return list;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        // 本list仅做模拟，实际项目中要根据具体业务逻辑来查询角色
        log.info("loginId: " + loginId, "loginType: " + loginType);
        List<String> list = rolePermissionService.getRolesByUserId(Long.valueOf(loginId.toString()));
        log.info("用户角色列表：" + list);
        return list;
    }

}

